package com.ppz.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


import java.util.ArrayList;

import static springfox.documentation.service.ApiInfo.DEFAULT_CONTACT;


@Configuration
@EnableSwagger2 //开启swagger2（新版）
public class SwaggerConfig {

    //配置了Swagger的Docket的bean实例
    //enable：是否启动swagger，如果为false，则swagger不能在浏览器中访问
    @Bean
    public Docket docket() {
        return new Docket(DocumentationType.SWAGGER_2).
                apiInfo(apiInfo())
                .groupName("ppz")
                .enable(true)
                .select()
                //RequestHandlerSelectors,配置要扫描的接口的方式
                //basePackage：指定要扫描的包
                //any():扫描全部
                //none():不扫描
                //withClassAnnotation:扫描类上的注解，参数是一个注解的反射对象
                //withMethodAnnotation:扫描方法上的注解
                .apis(RequestHandlerSelectors.basePackage("com.ppz.controller"))
                //path():过滤扫描路径
                //.paths(PathSelectors.ant(""))
                .build();
    }

    //配置Swagger信息=apiInfo
    private ApiInfo apiInfo() {

        //作者信息
        Contact contact =new Contact("琦琦", "https://github.com/ppz", "1447720332@qq.com");
        return new ApiInfo("PPZ的SwaggerAPI文档",
                "简单点",
                "1.0",
                "https://github.com/ppz",
                contact,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList());

    }

}
//http://localhost:8081/swagger-ui.html